#!/bin/bash

# Build Linux kernel

# Copyright (C) 2003-2006 IBM
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.


CPUS=`grep processor /proc/cpuinfo | wc -l`
ARCH=`uname -m`
VERSION=2.6.18
# WARNING: If you update the kernel version that we use, be sure to
# update $POUNDER_SRCDIR/memtest.patch, $POUNDER_HOME/test_scripts/memtest,
# $POUNDER_HOME/test_scripts/build_kernel, and
# $POUNDER_HOME/build_scripts/build_kernel.

#LOG_ALL_MAKE=1

# Decompress tarball if necessary
cd "$POUNDER_TMPDIR"
if [ ! -d linux-$VERSION ]; then
	tar -xzf "$POUNDER_OPTDIR/linux-$VERSION.tar.gz"
fi

# Clean up the tree.
cd linux-$VERSION
make mrproper

# Create a config file
make allmodconfig

# Build system
if [ $LOG_ALL_MAKE ]; then
	#Let all ouput flow to the external logging 
	make -j$CPUS oldconfig
       	time make -j$CPUS
else
	#Just log std err
	make -j$CPUS oldconfig > /dev/null
	time make -j$CPUS > /dev/null
fi 

# Did we get a kernel image?
RETCODE=1
if [ -f vmlinux ]; then
	RETCODE=0
fi

exit $RETCODE
